
/*-------------------------------------------------------------------------
 *
 * logicalmsgdesc.c
 *	  rmgr descriptor routines for replication/logical/message.c
 *
 * Portions Copyright (c) 2015-2022, PostgreSQL Global Development Group
 *
 *
 * IDENTIFICATION
 *	  src/backend/access/rmgrdesc/logicalmsgdesc.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include "replication/message.h"

void logicalmsg_desc(StringInfo fc_buf, XLogReaderState *fc_record)
{
	char	   *fc_rec = XLogRecGetData(fc_record);
	uint8		fc_info = XLogRecGetInfo(fc_record) & ~XLR_INFO_MASK;

	if (fc_info == XLOG_LOGICAL_MESSAGE)
	{
		xl_logical_message *fc_xlrec = (xl_logical_message *) fc_rec;
		char	   *fc_prefix = fc_xlrec->message;
		char	   *fc_message = fc_xlrec->message + fc_xlrec->prefix_size;
		char	   *fc_sep = "";

		Assert(fc_prefix[fc_xlrec->prefix_size - 1] == '\0');

		appendStringInfo(fc_buf, "%s, prefix \"%s\"; payload (%zu bytes): ",
						 fc_xlrec->transactional ? "transactional" : "non-transactional",
						 fc_prefix, fc_xlrec->message_size);
		/* 将消息负载写为一系列十六进制字节 */
		for (int fc_cnt = 0; fc_cnt < fc_xlrec->message_size; fc_cnt++)
		{
			appendStringInfo(fc_buf, "%s%02X", fc_sep, (unsigned char) fc_message[fc_cnt]);
			fc_sep = " ";
		}
	}
}

const char * logicalmsg_identify(uint8 fc_info)
{
	if ((fc_info & ~XLR_INFO_MASK) == XLOG_LOGICAL_MESSAGE)
		return "MESSAGE";

	return NULL;
}
